<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Introduce extends Model
{
    protected $table = 'introduce';//活动表
    public $timestamps = false;
    protected $guarded = [
       ];


    //介绍首页
    public function get($search = [], $page = 1, $length = 20 ){
        $IntroduceList = array();
        $IntroduceList['pageData'] = array();

        $sql = \DB::table($this->table)
            ->whereNull('deleted_at');

        if(isset($search['introduce'])){
            $sql->where('introduce', 'like', "%".$search['introduce']."%");
        }

        $IntroduceList['pageData']['count']     = $sql->count();
        $IntroduceList['pageData']['lastPage']  = ceil($IntroduceList['pageData']['count'] / $length);

        $IntroduceList['list'] = $sql->orderBy('sort', 'desc')
            ->skip(($page-1) * $length)->take($length)
            ->get();

        return $IntroduceList;
    }
    //修改
    public function saveEdit($data,$id){
            return \DB::table($this->table)->where('id',$id)->update($data);
    }
    //删除
    public function Del($data,$id){
        return \DB::table($this->table)->where('id',$id)->update($data);
    }

}